//
//	MVData.m
//
//	Create by mafeng on 13/8/2016
//	Copyright © 2016. All rights reserved.
//	Model file generated using JSONExport: https://github.com/Ahmed-Ali/JSONExport



#import "MVData.h"

NSString *const kMVDataContents = @"contents";
NSString *const kMVDataMvShowPlay = @"mv_show_play";

@interface MVData ()
@end
@implementation MVData




/**
 * Instantiate the instance using the passed dictionary values to set the properties values
 */

-(instancetype)initWithDictionary:(NSDictionary *)dictionary
{
	self = [super init];
	if(![dictionary[kMVDataContents] isKindOfClass:[NSNull class]]){
		self.contents = [[MVContent alloc] initWithDictionary:dictionary[kMVDataContents]];
	}

	if(dictionary[kMVDataMvShowPlay] != nil && [dictionary[kMVDataMvShowPlay] isKindOfClass:[NSArray class]]){
		NSArray * mvShowPlayDictionaries = dictionary[kMVDataMvShowPlay];
		NSMutableArray * mvShowPlayItems = [NSMutableArray array];
		for(NSDictionary * mvShowPlayDictionary in mvShowPlayDictionaries){
			MVMvShowPlay * mvShowPlayItem = [[MVMvShowPlay alloc] initWithDictionary:mvShowPlayDictionary];
			[mvShowPlayItems addObject:mvShowPlayItem];
		}
		self.mvShowPlay = mvShowPlayItems;
	}
	return self;
}


/**
 * Returns all the available property values in the form of NSDictionary object where the key is the approperiate json key and the value is the value of the corresponding property
 */
-(NSDictionary *)toDictionary
{
	NSMutableDictionary * dictionary = [NSMutableDictionary dictionary];
	if(self.contents != nil){
		dictionary[kMVDataContents] = [self.contents toDictionary];
	}
	if(self.mvShowPlay != nil){
		NSMutableArray * dictionaryElements = [NSMutableArray array];
		for(MVMvShowPlay * mvShowPlayElement in self.mvShowPlay){
			[dictionaryElements addObject:[mvShowPlayElement toDictionary]];
		}
		dictionary[kMVDataMvShowPlay] = dictionaryElements;
	}
	return dictionary;

}

/**
 * Implementation of NSCoding encoding method
 */
/**
 * Returns all the available property values in the form of NSDictionary object where the key is the approperiate json key and the value is the value of the corresponding property
 */
- (void)encodeWithCoder:(NSCoder *)aCoder
{
	if(self.contents != nil){
		[aCoder encodeObject:self.contents forKey:kMVDataContents];
	}
	if(self.mvShowPlay != nil){
		[aCoder encodeObject:self.mvShowPlay forKey:kMVDataMvShowPlay];
	}

}

/**
 * Implementation of NSCoding initWithCoder: method
 */
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
	self = [super init];
	self.contents = [aDecoder decodeObjectForKey:kMVDataContents];
	self.mvShowPlay = [aDecoder decodeObjectForKey:kMVDataMvShowPlay];
	return self;

}

@end
